<template>
	<el-dialog
	    :title="!dataForm.id ? '新增' : '修改'"
	    v-if="isAuth(['ROOT', 'MEDICAL_DEPT_SUB:INSERT', 'MEDICAL_DEPT_SUB:UPDATE'])"
	    :close-on-click-modal="false"
	    v-model="visible"
	    width="450px"
	>
	    <el-form :model="dataForm" ref="dataForm" :rules="dataRule" label-width="80px">
	        <el-form-item label="操作者" prop="operator">
	            <el-input v-model="dataForm.operator" style="width:100%" clearable />
	        </el-form-item>
	        <!-- <el-form-item label="操作者" prop="deptId">
	            <el-select v-model="dataForm.deptId" class="input" placeholder="选择科室" clearable="clearable">
	                <el-option v-for="one in deptList" :label="one.name" :value="one.id" />
	            </el-select>
	        </el-form-item> -->
	        <el-form-item label="信息" prop="message">
	            <el-input
	                v-model="dataForm.message"
	                type="textarea"
	                :rows="2"
	                style="width:100%"
	                maxlength="50"
	                show-word-limit
	                clearable
	            />
	        </el-form-item>
	    </el-form>
	    <template #footer>
	        <span class="dialog-footer">
	            <el-button @click="visible = false">取消</el-button>
	            <el-button type="primary" @click="dataFormSubmit">确定</el-button>
	        </span>
	    </template>
	</el-dialog>
</template>

<script>
export default {
	data: function() {
		return {
			visible: false,
			dataForm: {
				id: null,
				operator: null,
				message: null,
				createTime: null
			},
			dataRule: {
				message: [{ required: true, pattern: '^[a-zA-Z0-9\u4e00-\u9fa5,.;:?!@#$%^&*()_+=\\-<>{}\\[\\]\\\\|\'\"`~“”]{2,500}$', message: '格式错误' }]
			}
		};
	},

	methods: {
		reset: function() {
		    let dataForm = {
		        id: null,
		        operator: null,
		        message: null,
		        createTime: null
		    };
		    this.dataForm = dataForm;
		},
		init: function(id) {
		    let that = this;
		    that.reset();
		    that.dataForm.id = id || 0;
		    that.visible = true;
		    that.$nextTick(() => {
		        that.$refs['dataForm'].resetFields();
		        // TODO 查询科室用于修改业务
				if (id) {
				            that.$http('/message/searchById', 'POST', { id: id }, true, function(resp) {
				                that.dataForm.id = resp.id;
				                that.dataForm.operator = resp.operator;
				                that.dataForm.message = resp.message;
				                that.dataForm.createTime = resp.createTime;
				            });
				        }
		    });
		},
		dataFormSubmit: function() {
		    let that = this;
		    this.$refs['dataForm'].validate(valid => {
		        if (valid) {
		            that.$http(
		                `/message/${!that.dataForm.id ? 'insert' : 'update'}`,
		                'POST',
		                that.dataForm,
		                true,
		                function(resp) {
		                    ElMessage({
		                        message: '操作成功',
		                        type: 'success'
		                    });
		                    that.visible = false;
		                    that.$emit('refreshDataList');
		                }
		            );
		        }
		    });
		}
	}
};
</script>

<style>
</style>